builtin icon: set a baseline
authorMatthias Clasen <mclasen@redhat.com>
Mon, 18 Jan 2016 02:02:18 +0000 (21:02 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 18 Jan 2016 02:02:18 +0000 (21:02 -0500)
Most uses of builtin icons (check and radio buttons,
expanders, etc) are placed next to labels, so they should
be properly positioned wrt to the baseline. Lacking anything
better, give the builtin icons a baseline that places the
center of the icon at the strikethrough position.

gtk/gtkbuiltinicon.c

index 8e543e5f11f6eb4bc6bfc120581a806331404e86..8b9957344605f6d24a8d6b8befed44a257db6bde 100644 (file)
@@ -63,6 +63,10 @@ gtk_builtin_icon_get_preferred_size (GtkCssGadget   *gadget,
                                      gint           *natural_baseline)
 {
   GtkBuiltinIconPrivate *priv = gtk_builtin_icon_get_instance_private (GTK_BUILTIN_ICON (gadget));
+  GtkWidget *widget;
+  PangoContext *pango_context;
+  PangoFontMetrics *metrics;
+  int strikethrough;
   double min_size;
   guint property;
 
@@ -73,27 +77,42 @@ gtk_builtin_icon_get_preferred_size (GtkCssGadget   *gadget,
   min_size = _gtk_css_number_value_get (gtk_css_style_get_value (gtk_css_gadget_get_style (gadget), property), 100);
   if (min_size > 0.0)
     {
-      *minimum = *natural = 0;
-      return;
+      *minimum = *natural = min_size;
     }
-
-  if (priv->default_size_property)
+  else if (priv->default_size_property)
     {
       GValue value = G_VALUE_INIT;
 
       /* Do it a bit more complicated here so we get warnings when
-       * somebody sets a non-int proerty. */
+       * somebody sets a non-int proerty.
+       */
       g_value_init (&value, G_TYPE_INT);
       gtk_widget_style_get_property (gtk_css_gadget_get_owner (gadget),
                                      priv->default_size_property,
                                      &value);
       *minimum = *natural = g_value_get_int (&value);
       g_value_unset (&value);
-      return;
     }
+  else
+    {
+      *minimum = *natural = priv->default_size;
+    }
+
+  widget = gtk_css_gadget_get_owner (gadget);
+
+  pango_context = gtk_widget_get_pango_context (widget);
+  metrics = pango_context_get_metrics (pango_context,
+                                       pango_context_get_font_description (pango_context),
+                                       pango_context_get_language (pango_context));
+
+  strikethrough = pango_font_metrics_get_strikethrough_position (metrics);
+
+  if (minimum_baseline)
+    *minimum_baseline = *minimum * 0.5 + PANGO_PIXELS (strikethrough);
+  if (natural_baseline)
+    *natural_baseline = *minimum_baseline;
 
-  *minimum = priv->default_size;
-  *natural = priv->default_size;
+  pango_font_metrics_unref (metrics);
 }
 
 static void